<?php
// Obtener contactos activos
$cobranzas = Cobranza::model()->activos()->de_contacto($model->id)->findAll();
?>
<div class="widget blue">
    <div class="widget-title">
        <h4> <i class="icon-money"></i> <?php echo Cobranza::label(2) ?></h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <a href="javascript:;" class="icon-remove"></a>
        </span>
    </div>
    <div class="widget-body">

        <?php if ($cobranzas): ?>
            <div style='overflow:auto'> 
                <?php
                $this->widget('ext.selgridview.BootSelGridView', array(
                    'id' => 'cobranza-grid',
                    'afterAjaxUpdate' => "function(id,data){AjaxActualizarActividades();}",
                    'type' => 'striped bordered hover advance',
                    'dataProvider' => new CArrayDataProvider($cobranzas, array('pagination' => array('pageSize' => 5))),
                    'selectableRows' => 2,
                    'columns' => array(
                        array(
                            'name' => 'Nombre',
                            'value' => 'CHtml::link($data->nombre,"",array("id"=>$data->id,"onClick"=>"viewModal(\'cobranzas/cobranza/view/id/".$data->id."\',function(){})"))',
                            'type' => 'raw',
                        ),
                        array(
                            'header' => 'Monto',
                            'name' => 'monto_cuota',
                            'value' => '"$".number_format($data->monto_cuota, 2)'
                        ),
                        array(
                            'header' => 'Fecha Vencimiento',
                            'name' => 'fecha_vencimiento',
                            'type' => 'html',
                            'value' => 'Util::FormatDate($data->fecha_vencimiento, "d/m/Y");'
                        ),
                        array(
                            'class' => 'CButtonColumn',
                            'template' => '{update} {delete}',
                            'buttons' => array(
                                'update' => array(
                                    'label' => '<button class="btn btn-primary"><i class="icon-pencil"></i></button>',
                                    'options' => array('title' => 'Actualizar'),
                                    'url' => 'Yii::app()->createUrl("cobranzas/cobranza/update", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_cobranza_update"))',
                                ),
                                'delete' => array(
                                    'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                    'options' => array('title' => 'Eliminar'),
                                    'url' => 'Yii::app()->createUrl("cobranzas/cobranza/delete", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_cobranza_delete"))',
                                ),
                            ),
                            'htmlOptions' => array(
                                'width' => '80px'
                            )
                        ),
                    ),
                ));
                ?>
            </div>
            <br>

        <?php endif; ?>

        <?php
        Util::checkAccess(array("action_cobranza_create")) ?
                        $this->widget(
                                'bootstrap.widgets.TbButton', array(
                            'id' => 'add-Cobranza',
                            'label' => ($cobranzas ? '' : '<br>') . 'Agregar Cobranza',
                            'encodeLabel' => false,
                            'icon' => $cobranzas ? 'plus-sign' : 'usd',
                            'htmlOptions' => array(
                                'onClick' => 'js:viewModal("cobranzas/cobranza/create/id_cuenta/' . $model->cuenta->id . '/id_contacto/' . $model->id . '",function(){'
                                . 'maskAttributes();})',
                                'class' => $cobranzas ? '' : 'empty-portlet',
                            ),
                                )
                        ) : '';
        ?>
    </div>
</div>